package core

import (
	"flag"
	"fmt"
	"io/ioutil"

	"gopkg.in/yaml.v2"
)

var AppConfig *AppConfigDto = nil

func LoadConfig() {
	configFile := flag.String("c", "config/config.yml", "config file")
	flag.Parse()

	fileByte, err := ioutil.ReadFile(*configFile)
	if err != nil {
		fmt.Println("ConfigFile Load Fail")
		panic(err)
	}

	err = yaml.Unmarshal(fileByte, &AppConfig)
	if err != nil {
		fmt.Println("ConfigFile Parse Fail")
		panic(err)
	}
}

type AppConfigDto struct {
	DatabaseConfig
	RedisConfig
}

type DatabaseConfig struct {
	Host        string
	User        string
	Password    string
	Name        string
	TablePrefix string
}

type RedisConfig struct {
	Host string
	Auth string
}
